import os
import openai

os.environ["http_proxy"] = "http://127.0.0.1:7890" 
os.environ["https_proxy"] = "http://127.0.0.1:7890"

f = open("api.txt")  #  提前将api key保存在api.txt中
openai.api_key = f.read()

response = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
        {"role": "system", "content": "我提供单词，你按照特定格式返回该单词的词性、音标、2个相同意思的描述、3个简单的例子。"},
        {"role": "user", "content":"assumption"},
        {"role": "assistant", "content":"#assumption(n)\n#d assumption音标\n/əˈsʌmpʃn/\n#d assumption描述1\nsomething that you accept as true without question or proof\n#d assumption描述2\nIf you make an assumption that something is true or will happen, you accept that it is true or will happen, often without any real proof.\n#e assumption例子1\nThey make the naive assumption that because it's popular it must be good.\n#e assumption例子2\nLots of evidence supports this assumption.\n#e assumption例子3\nI really don't like you making assumptions about what I think."},
        {"role": "user", "content":"incorporate"},
        {"role": "assistant", "content":"#incorporate(v)\n#d incorporate音标\n/ɪnˈkɔːpəreɪt/\n#d incorporate描述1\nto include something as part of something larger\n#d incorporate描述2\nIf one thing incorporates another thing, it includes the other thing.\n#e incorporate例子1\nMany of your suggestions have been incorporated in the plan.\n#e incorporate例子2\nThe new car design incorporates all the latest safety features.\n#e incorporate例子3\nThis design incorporates the best features of our earlier models."},
        {"role": "user", "content":"comprehensive"},
        {"role": "assistant", "content": "#comprehensive(adj)\n#d comprehensive音标\n/ˌkɒm.prɪˈhen.sɪv/\n#d comprehensive描述1\ncomplete and including everything that is necessary.\n#d comprehensive描述2\nincluding all, or almost all, the items, details, facts, information, etc., that may be involved\n#e comprehensive例子1\nIs this list comprehensive or are there some names missing?\n#e comprehensive例子2\nHe has written a fully comprehensive guide to Rome.\n#e comprehensive例子3\nIf you are a young, inexperienced driver, it is worth having comprehensive insurance."},
        {"role": "user", "content": "awesome"} # 这里根据自身需要修改成别的单词
    ]
)

print(response)
print(response['choices'][0]['message']['content'])